package containers;

import dbadapters.checkConnection;
import entities.CoSigner;
import entities.FinancialInfo;
import entities.Loan;
import entities.PaymentPlan;
import entities.Student;

import java.util.Date;
import java.util.HashMap;

/**
 * A singleton class to access the dictionary containing the customers.
 */
public class StudentContainer {

	/** Private constructor to ensure that no instance is created. */
	private StudentContainer() {
	}

	/** The dictionary for accessing Students */
	private static HashMap<Integer, Student> dictionary;

	/**
	 * Return the dictionary that maps unique ids to Students
	 * 
	 * @return the dictionary that maps ids to students
	 */
	public static HashMap<Integer, Student> dictionary() {
		if (dictionary == null) {
			/* Create the initial dictionary. */
			dictionary = new HashMap<Integer, Student>(10);

			// if db conncection doesn't work, hard code some examples
			checkConnection c = new checkConnection();

			if (!c.isConnectionValid()) {
				// add students to dictionary
				Student student1 = new Student(123456, "123456");
				student1.setAddress("123 Fake St");
				student1.setBirthdate("01/01/2005");
				student1.setCitizenship(true);
				student1.setEmail("123@google.com");
				student1.setFatherEducation(Student.education.DEGREE);
				student1.setInstitution("UofS");
				student1.setName("Stewie Griffin");
				student1.setSIN("465467823");
				student1.setPhoneNumber("222-2222");
				student1.setMotherEducation(Student.education.HIGH_SCHOOL);
				student1.setMaritalStatus(Student.maritalStatuses.SINGLE);

				Loan loan1 = new Loan(student1);
				loan1.setAmountRequested(5000.00);
				loan1.setIsNew(true);
				student1.setLoan(loan1);

				FinancialInfo finInfo1 = new FinancialInfo();
				finInfo1.setChildSupport(0);
				finInfo1.setHouseholdIncome(100000);
				finInfo1.setPersonalIncome(10000);
				finInfo1.setScholarship(0);
				finInfo1.setTaxableEarnings(0);
				student1.setFinances(finInfo1);

				CoSigner cosigner1 = new CoSigner(789789);
				cosigner1.setName("Cleveland");
				cosigner1.setAddress("346 Spooner St, Quahog, RI, USA");
				cosigner1.setBirthdate(new Date(71, 11, 17));
				cosigner1.setEmail("cleveland@gmail.com");
				cosigner1.setPhoneNumber("555-555-5554");
				FinancialInfo finInfo2 = new FinancialInfo();
				finInfo2.setChildSupport(0);
				finInfo2.setHouseholdIncome(100000);
				finInfo2.setPersonalIncome(10000);
				finInfo2.setMonthlyExpenses(1000);
				finInfo2.setScholarship(0);
				finInfo2.setTaxableEarnings(0);
				cosigner1.setFinancialInfo(finInfo2);
				loan1.setCosigner(cosigner1);

				dictionary.put(123456, student1);
				NewLoanContainer.dictionary().put(123456, student1);

				Student student2 = new Student(654321, "654321");
				student2.setAddress("111 Fake St");
				student2.setBirthdate("01/01/1975");
				student2.setCitizenship(false);
				student2.setEmail("321@google.com");
				student2.setFatherEducation(Student.education.DIPLOMA);
				student2.setInstitution("UofS");
				student2.setName("Peter Griffin");
				student2.setSIN("123123123");
				student2.setPhoneNumber("222-2266");
				student2.setMotherEducation(Student.education.NONE);
				student2.setMaritalStatus(Student.maritalStatuses.MARRIED);

				Loan loan2 = new Loan(student2);
				loan2.setAmountRequested(5000.00);
				loan2.setAmountGiven(5000.00);
				loan2.setIsNew(false);
				loan2.setApproval(true);
				student2.setLoan(loan2);

				PaymentPlan plan = new PaymentPlan(loan2.getAmountGiven());
				plan.setAmountReceived(416.67);
				plan.setNextAmount(416.67);
				plan.setPrevAmount(416.67);
				plan.setNextDate(new Date(110, 12, 1));
				plan.setPrevDate(new Date(110, 11, 1));
				student2.setPaymentPlanCreated(true);
				student2.setPaymentPlan(plan);

				CoSigner cosigner2 = new CoSigner(789788);
				cosigner2.setName("Quagmire");
				cosigner2.setAddress("344 Spooner St, Quahog, RI, USA");
				cosigner2.setBirthdate(new Date(70, 10, 4));
				cosigner2.setEmail("quagmire@gmail.com");
				cosigner2.setPhoneNumber("555-555-5555");
				FinancialInfo finInfo4 = new FinancialInfo();
				finInfo4.setChildSupport(0);
				finInfo4.setHouseholdIncome(50000);
				finInfo4.setPersonalIncome(50000);
				finInfo4.setMonthlyExpenses(4000);
				finInfo4.setScholarship(0);
				finInfo4.setTaxableEarnings(50000);
				cosigner2.setFinancialInfo(finInfo4);
				loan2.setCosigner(cosigner2);

				FinancialInfo finInfo3 = new FinancialInfo();
				finInfo3.setChildSupport(20000);
				finInfo3.setHouseholdIncome(50000);
				finInfo3.setPersonalIncome(50000);
				finInfo3.setScholarship(0);
				finInfo3.setTaxableEarnings(50000);
				student2.setFinances(finInfo3);

				dictionary.put(654321, student2);

				Student student3 = new Student(012345, "012345");
				student3.setAddress("456 Fake St");
				student3.setBirthdate("01/01/1972");
				student3.setCitizenship(true);
				student3.setEmail("584@google.com");
				student3.setFatherEducation(Student.education.DEGREE);
				student3.setInstitution("UofS");
				student3.setName("Lois Griffin");
				student3.setSIN("465467898");
				student3.setPhoneNumber("222-2222");
				student3.setMotherEducation(Student.education.HIGH_SCHOOL);
				student3.setMaritalStatus(Student.maritalStatuses.MARRIED);

				Loan loan3 = new Loan(student3);
				loan3.setAmountRequested(5000.00);
				loan3.setIsNew(true);
				student3.setLoan(loan3);

				CoSigner cosigner3 = new CoSigner(789787);
				cosigner3.setName("Joe");
				cosigner3.setAddress("348 Spooner St, Quahog, RI, USA");
				cosigner3.setBirthdate(new Date(65, 9, 14));
				cosigner3.setEmail("joe@gmail.com");
				cosigner3.setPhoneNumber("555-555-5556");
				FinancialInfo finInfo5 = new FinancialInfo();
				finInfo5.setChildSupport(0);
				finInfo5.setHouseholdIncome(50000);
				finInfo5.setPersonalIncome(50000);
				finInfo5.setMonthlyExpenses(4000);
				finInfo5.setScholarship(0);
				finInfo5.setTaxableEarnings(50000);
				cosigner3.setFinancialInfo(finInfo5);
				loan3.setCosigner(cosigner3);

				FinancialInfo finInfo6 = new FinancialInfo();
				finInfo6.setChildSupport(200000);
				finInfo6.setHouseholdIncome(600000);
				finInfo6.setPersonalIncome(10000);
				finInfo6.setScholarship(1000);
				finInfo6.setTaxableEarnings(1000);
				student3.setFinances(finInfo6);

				dictionary.put(012345, student3);
				NewLoanContainer.dictionary().put(012345, student3);
			}

		}
		return dictionary;
	}

}
